package com.thymeleaf.demo.config;

import com.thymeleaf.demo.myinterceptor.AdminInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class GlobalConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry){
        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/static/")
                .addResourceLocations("classpath:/public/")
                .addResourceLocations("classpath:/resource/");
    }

    /**
     * 注入自定义拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry){
        // 创建拦截器实现类对象
        AdminInterceptor myInterceptor = new AdminInterceptor();
        List<String> urls = new ArrayList<>();
        urls.add("/mall/admin/**");
        List<String> excludeUrls = new ArrayList<>();
        excludeUrls.add("/mall/admin/login");
        /*
        excludePathPatterns：不需要拦截的路由
        addPathPatterns：需要拦截的路由
         */
        registry.addInterceptor(myInterceptor)
                .addPathPatterns(urls).
                excludePathPatterns(excludeUrls);
    }

    public void setOutputDir(String outputDir) {
    }

    public void setOpen(boolean b) {
    }

    public void setBaseResultMap(boolean b) {
    }

    public void setBaseColumnList(boolean b) {
    }

    public void setAuthor(String author) {
    }

    public void setMapperName(String s) {
    }

    public void setXmlName(String s) {
    }

    public void setServiceName(String s) {
    }

    public void setServiceImplName(String s) {
    }

    public void setControllerName(String s) {
    }
}
